package com.example.iot.controller;

import com.example.iot.mapper.IotDataMapper;
import com.example.iot.service.IotDataService;
import com.example.iot.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.io.IOException;

/**
 * @author : Lin
 * @version : [v1.0]
 * @className : IotDataController
 * @description : 描述说明该类的功能
 * @createTime : 2023/7/3 22:20
 * @updateUser : Lin
 * @updateTime : 2023/7/3 22:20
 * @updateRemark : 描述说明本次修改内容
 */
@RestController
@RequestMapping("/iot")
public class IotDataController {

    @Autowired
    private IotDataService iotDataService;
    @Autowired
    private IotDataMapper iotDataMapper;

    @RequestMapping("/getcurrentdata")
    public R GetCurrentData() throws IOException {
        return iotDataService.GetSensorData();
    }

    @RequestMapping("/getalldata")
    public R GetAllData(){
        return iotDataService.ListAllIotData();
    }

    @RequestMapping("/getavgdata")
    public R GetAvgData(){
        return R.ok(iotDataMapper.get_average_data());
    }
}
